package com.nowcoder.community.util;

import org.omg.CORBA.PRIVATE_MEMBER;

/**
 * @ClassName RedisKeyUtil
 * @Description
 * @Author hhwu
 * @Date 2022/5/25 16:07
 * Version 1.0
 **/
public class RedisKeyUtil {
    private static final String SPLIT = ":";
    private static final String PREFIX_ENTITY_LIKE = "like:entity";// 帖子获得的赞
    private static final String PREFIX_USER_LIKE = "like:user";// 用户获得的赞
    private static final String PREFIX_FOLLOWEE = "followee";// 被关注者
    private static final String PREFIX_FOLLOWER = "follower";// 关注者（粉丝）
    private static final String PREFIX_KAPTCHA = "kaptcha";// 验证码
    private static final String PREFIX_TICKET = "ticket";// 登录凭证
    private static final String PREFIX_USER = "user";// 缓存用户
    private static final String PREFIX_UV = "uv"; // 单日登录和游客用户
    private static final String PREFIX_DAU = "dau";// 单日登录用户
    private static final String PREFIX_POST = "post";// 帖子分数

    //某个实体（帖子或评论）的赞
    // like:entity:entityType:entityId -> set(userId)
    public static String getEntityLikeKey(int entityType, int entityId) {
        /**
         * @Author hhwu
         * @Description //TODO 返回一个实体的key
         * @Date 16:11 2022/5/25
         * @Param [entityType, entityId]
         * @return java.lang.String
         **/
        return PREFIX_ENTITY_LIKE + SPLIT + entityType + SPLIT + entityId;
    }

    // 某个用户获得的赞
    // like:user:userId -> int
    public static String getUserLikeKey(int userId) {
        /**
         * @Author hhwu
         * @Description //TODO 返回一个用户的key
         * @Date 17:48 2022/5/25
         * @Param [userId]
         * @return java.lang.String
         **/
        return PREFIX_USER_LIKE + SPLIT + userId;
    }

    // 某个用户关注的实体（人，帖子，题目等）
    // followee:userId:entityType->zset(entityId, time)
    public static String getFolloweeKey(int userId, int entityType) {
        /**
         * @Author hhwu
         * @Description //TODO 返回用户关注的实体目标key
         * @Date 10:07 2022/5/26
         * @Param [userId, entityType]
         * @return java.lang.String
         **/
        return PREFIX_FOLLOWEE + SPLIT + userId + SPLIT + entityType;
    }

    // 某个实体拥有的粉丝
    // follower:entityType:entityId -> zset(userId,time)
    public static String getFollowerKey(int entityType, int entityId) {
        /**
         * @Author hhwu
         * @Description //TODO 返回某个实体拥有的粉丝key
         * @Date 10:10 2022/5/26
         * @Param [entityType, entityId]
         * @return java.lang.String
         **/
        return PREFIX_FOLLOWER + SPLIT + entityType + SPLIT + entityId;
    }

    //登陆验证码
    public static String getKaptchaKey(String owner) {
        /**
         * @Author hhwu
         * @Description //TODO 登录验证码，owner是临时标识用户，时用户和数据库中存放的验证码对应
         * @Date 17:06 2022/5/26
         * @Param [owner]
         * @return java.lang.String
         **/
        return PREFIX_KAPTCHA + SPLIT + owner;
    }

    //登陆的凭证
    public static String getTicketKey(String ticket) {
        /**
         * @Author hhwu
         * @Description //TODO 以和ticket字符串相关的key存放ticket的整个对象
         * @Date 17:09 2022/5/26
         * @Param [ticket]
         * @return java.lang.String
         **/
        return PREFIX_TICKET + SPLIT + ticket;
    }

    //用户
    public static String getUserKey(int userId) {
        /**
         * @Author hhwu
         * @Description //TODO 获取用户的key
         * @Date 17:54 2022/5/26
         * @Param [userId]
         * @return java.lang.String
         **/
        return PREFIX_USER + SPLIT + userId;
    }

    //单日访问UV
    public static String getUVKey(String date) {
        /**
         * @Author hhwu
         * @Description //TODO 统计单日用户和游客的key
         * @Date 14:36 2022/6/1
         * @Param [date]
         * @return java.lang.String
         **/
        return PREFIX_UV + SPLIT + date;
    }
    
    //区间UV
    public static String getUVKey(String startDate, String endDate) {
        /**
         * @Author hhwu
         * @Description //TODO 方法重载，区间统计用户和游客的key，输入开始和截止日期
         * @Date 14:37 2022/6/1
         * @Param [startDate, endDate]
         * @return java.lang.String
         **/
        return PREFIX_UV + SPLIT +startDate + endDate;
    }
    //单日活跃用户
    public static String getDAUKey(String date) {
        /**
         * @Author hhwu
         * @Description //TODO 单日活跃用户的key
         * @Date 14:37 2022/6/1
         * @Param [date]
         * @return java.lang.String
         **/
        return  PREFIX_DAU + SPLIT + date;
    }
    //区间活跃用户
    public static String getDAUKey(String startDate, String endDate) {
        /**
         * @Author hhwu
         * @Description //TODO 方法重载，区间活跃用户的key
         * @Date 14:38 2022/6/1
         * @Param [startDate, endDate]
         * @return java.lang.String
         **/
        return PREFIX_DAU + SPLIT + startDate + endDate;
    }

    public static String getPostScoreKey() {
        /**
         * @Author hhwu
         * @Description //TODO 帖子分数的key
         * @Date 20:50 2022/6/1
         * @Param []
         * @return java.lang.String
         **/
        return PREFIX_POST + SPLIT +"score";
    }
}
